<?php
// ==========================================================
// | Region
// ==========================================================
// | Time：2021/12/19 18:41
// ==========================================================
// | Author: 陈 <1035812848@qq.com>
// ==========================================================

namespace app\api\controller;

use app\common\controller\Api;
use app\common\model\UserRecyclerInfo;
use think\Db;

class Region extends Api
{

    public function init()
    {
        $regions    = \app\admin\model\Region::where(['status' => 1])->select();
        $info       = Db::name('UserRecyclerInfo')->where(['user_id' => $this->auth->id])->order('id DESC')->find();

        if ($info) {
            $info['positive']   = cdnurl($info['positive'], true);
            $info['back']       = cdnurl($info['back'], true);
        }

        foreach ($regions as &$v) {
            $v->hidden(['admin_id']);
            $v->alias = $v->name . '【' . $v->address . '】';
        }

        $this->success('', [
            'regions'           => $regions,
            'wechat_tmpl_ids'   => ['J9p2S3kKzrxzDuT67f0PVMFb7Voo5ma0mG9dbRTePOM'],
            'info'              => $info,
            'article_id'        => 3
        ]);
    }

    /**
     * Name: 回收员申请
     * Date: 2021/12/19 18:46
     */
    public function recyclerapplication()
    {
        $params             = $this->request->param();
        $params['user_id']  = $this->auth->id;
        $recyclerModel      = new UserRecyclerInfo();
        if (!$recyclerModel->recyclerApplication($params)) {
            $this->error($recyclerModel->getError());
        }

        $this->success();
    }

    /**
     * 附近回收员
     */
    public function recyclersnearby()
    {
        $params                 = [
            'site'  => $this->request->header('site')
        ];
        $userRecyclerInfoModel  = new UserRecyclerInfo();
        $this->success('', [
            'recycler' => $userRecyclerInfoModel->recyclersNearby($params)
        ]);
    }

}